/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fiap.servlet;

import br.com.fiap.codigo.Entidade;
import java.io.IOException;
import java.io.PrintWriter;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author rm64596
 */

@WebServlet (urlPatterns="/processarFormularioSatisfacao")

public class ProcessarSatisfacao extends HttpServlet {

    private EntityManagerFactory factory;
    private EntityManager motor;
    private EntityTransaction transação;

   
    public void init() throws ServletException {
        
        factory = Persistence.createEntityManagerFactory("sistemaWeb");
        
        motor = factory.createEntityManager();
        
        transação = motor.getTransaction();
    }
    
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        PrintWriter writer = resp.getWriter();
        
        Entidade satisfacao = new Entidade();
        
        satisfacao.setNome(req.getParameter("nome"));
        satisfacao.setComentario(req.getParameter("comentario"));
        satisfacao.setProduto(req.getParameter("produtos"));
        satisfacao.setSatisfacao(req.getParameter("satisfacao"));
        
        
        transação.begin();

	motor.persist(satisfacao);

	transação.commit();
        
         writer.println("Persistido com Sucesso !!" );
        
    }
    
    
    
}
